﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using YT.Commons;
using YT.DB;
using YT.Modules;


namespace YT.XH.MeniereDisease
{
    public partial class frmMDJocobsonMtn : Form
    {
        private FormStatus mfrmStatus;
        private string mstrSickRecID = string.Empty;
        private DBAccess mdbcon = new DBAccess(false, false);
        private string mstrTableName = "JocobsonHdr";
        public frmMDJocobsonMtn()
        {
            InitializeComponent();
        }
        public frmMDJocobsonMtn(string strSickRecID)
        {
            InitializeComponent();
            mstrSickRecID = strSickRecID;
        }
        public frmMDJocobsonMtn(string strSickRecID , FormStatus frmStatus)
        {
            InitializeComponent();
            mstrSickRecID = strSickRecID;
            mfrmStatus = frmStatus;
        }
        public frmMDJocobsonMtn(string strSickRecID, FormStatus frmStatus,string strSeqNo)
        {
            InitializeComponent();
            mstrSickRecID = strSickRecID;
            mfrmStatus = frmStatus;
        }

        private void FillBaseInfo()
        {
            string strSQL = string.Empty;
            strSQL = "select * from mSickPerson where sickRecID='" + mstrSickRecID + "'";
            DataRow drRow = mdbcon.GetDataFirstRow(strSQL);
            if (drRow != null)
            {
                txtSickName.Text = CvtFunc.ToString(drRow["SickName"]);
                txtAddress.Text = CvtFunc.ToString(drRow["Address"]);
                txtAddress.Text = CvtFunc.ToString(drRow["Phone"]) + CvtFunc.ToString(drRow["MobilePhone"]);
                txtRemark.Text = CvtFunc.ToString(drRow["Remark"]);
            }
        }

        private bool FillDetail()
        {
            this.dgvDetail.Rows.Clear();
            string strSQL = string.Empty;
            int intRow = 0;
            strSQL = "select * from " + mstrTableName + " where sickRecID='" + mstrSickRecID + "' and Type='" + TitleType.MeniereDisease + "'  order by SeqNo";
            DataTable dtDtl = mdbcon.GetDataTable(strSQL);
            foreach (DataRow drRow in dtDtl.Rows)
            {
                dgvDetail.Rows.Add();
                this.dgvDetail.Rows[intRow].Cells[colDate.Index].Value = BaseFunctions.FormatDate(CvtFunc.ToString(drRow["ExamDate"]), DateFormatOption.DateFmtYMD);
                this.dgvDetail.Rows[intRow].Cells[ColSeqNo.Index].Value = CvtFunc.ToString(drRow["SeqNo"]);
                intRow++;
            }
            return true;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {

        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            FormStatus mfrmStatus = new FormStatus();
            mfrmStatus = FormStatus.AddNew;
            frmMDJacobsonTitle frmJocobson = new frmMDJacobsonTitle(mstrSickRecID, mfrmStatus);
            frmJocobson.ShowDialog();
            FillDetail();
        }

        private void ShowMtn()
        {
            string strSeqNo = string.Empty;
            strSeqNo = CvtFunc.ToString(this.dgvDetail.CurrentRow.Cells[ColSeqNo.Index].Value);

            //这里写要填写的具体内容,就是“治疗前的MTN"
            FormStatus mfrmStatus = new FormStatus();
            mfrmStatus = FormStatus.Update;

            frmMDJacobsonTitle frmJocobson = new frmMDJacobsonTitle(mstrSickRecID, mfrmStatus, strSeqNo);
            frmJocobson.ShowDialog();
            FillDetail();
        }

        private void dgvDetail_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == colDetail.Index)
            {
                ShowMtn();
            }  
        }

        private void frmMDJocobsonMtn_Load(object sender, EventArgs e)
        {
            this.Text = "眩晕障碍评估表";
            FillBaseInfo();
            FillDetail();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
